#include "boarditem.h"
#include "constants.h"

#include <QPen>
#include <QBrush>
#include <QtCore>

BoardItem::BoardItem( int x, int y, QString filePath, QGraphicsItem* parent ) : QGraphicsSvgItem( filePath, parent )
{
  this->x = x;
  this->y = y;

  calculateSelfScenePos();
  setPos( scenePos );
  setZValue( getDefaultZValue() );
}

QPointF BoardItem::calculateScenePos( int x, int y )
{
  qreal x_scene_pos = ( x - int( Constants::BOARD_SIZE/2 ) ) * Constants::FIELD_SIZE - Constants::FIELD_SIZE/2;
  qreal y_scene_pos = ( -1 * ( y - Constants::BOARD_SIZE/2 ) ) * Constants::FIELD_SIZE - Constants::FIELD_SIZE/2;
  QPointF scenePos( x_scene_pos, y_scene_pos );
  return scenePos;
}

void BoardItem::calculateSelfScenePos()
{
  scenePos = calculateScenePos(x, y);
}

QPointF& BoardItem::getScenePos()
{
  return scenePos;
}

int BoardItem::getBoardX()
{
  return x;
}

int BoardItem::getBoardY()
{
  return y;
}

int BoardItem::getDefaultZValue()
{
  return Constants::FIELD_Z_LEVEL;
}

bool BoardItem::isMovable()
{
  return false;
}
